<?php

class TurnoverPriceGetter extends CActiveRecordBehavior {
	public function getTurnoverPrice($attribute = 'price_dealer', $time = null) {
		
		if($time) {
			$model = $this->owner;
			$criteria = new CDbCriteria(array(
				'condition' => "goods_id = '{$model->id}' AND `datetime` LIKE '{$time}%'"
			));
			$activePrice = GoodsActivePrice::model()->find($criteria);
			if($activePrice) return $activePrice->{$attribute};
		}
		
		return $this->getOwner()->priceInfo->{$attribute};
	}
}

?>